package com.zhong.gang.applib.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import com.zhong.gang.applib.R;
import com.zhong.gang.applib.databinding.LayoutTitlebarLeftTitleBinding;
import com.zhong.gang.applib.databinding.LayoutTitlebarRightTitleBinding;


public class LeftTitleView extends FrameLayout {
    private LayoutTitlebarLeftTitleBinding binding;
    public LeftTitleView(@NonNull Context context) {
        super(context);
        init();
    }

    public LeftTitleView(@NonNull Context context, @NonNull AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public LeftTitleView(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_titlebar_left_title,null);
        this.addView(view);
        binding  = DataBindingUtil.bind(view);
    }

    public void setContent(int title){
        binding.text.setText(title+"");
        binding.text.setVisibility(title>0?VISIBLE:GONE);
    }

    public void setImgRes(@DrawableRes int res){
        binding.icon.setImageResource(res);
        binding.icon.setVisibility(VISIBLE);
    }
}
